import http from '@/util/request.js'

export default {
    // 根据id获取商品信息
    getGoodsById: (id) => {
        return http({
            url: `/api/goods/id/${id}`,
            method: 'get'
        })
    },

    // 获取商品列表
    getGoodsList: (data) => {
        return http({
            url: '/api/goods/list',
            method: 'get',
            params: data
        })
    },

    // 根据分类获取商品
    getGoodsByCategory: (category) => {
        return http({
            url: `/api/goods/category/${category}`,
            method: 'get'
        })
    },

    // 添加商品
    addGoods: (data) => {
        return http({
            url: '/api/goods/add',
            method: 'post',
            data
        })
    },

    // 更新商品
    updateGoods: (data) => {
        return http({
            url: '/api/goods/update',
            method: 'put',
            data
        })
    },

    // 删除商品(软删除)
    deleteGoods: (id) => {
        return http({
            url: `/api/goods/delete/${id}`,
            method: 'delete'
        })
    },

    // 切换商品状态(上下架)
    reverseStatus: (id) => {
        return http({
            url: `/api/goods/status/${id}`,
            method: 'post'
        })
    },

    // 获取商品分页列表
    getGoodsPage: (current, size, data) => {
        return http({
            url: '/api/goods/page',
            method: 'get',
            params: {
                current: current,
                size: size,
                ...data
            }
        })
    },
}
